layui.use(['form', 'layer', 'jquery', 'table', 'laydate', 'upload'], function () {
    var table = layui.table;
    var laydate = layui.laydate;
    var form = layui.form;

    form.render();

    var myDate = new Date();//获取当前时间设置选择时间的范围
    myDate.setTime(myDate.getTime()-24*60*60*1000);
    var maxtime = myDate.getFullYear() + "-" + (myDate.getMonth() + 1).toString().padStart(2, '0') + "-" + (myDate.getDate()).toString().padStart(2, '0');

    laydate.render({
        elem: '#startTime'
        ,format: 'yyyy-MM-dd'
        ,value: maxtime
    });

    laydate.render({
        elem: '#endTime'
        ,format: 'yyyy-MM-dd'
        ,value: maxtime
    });

    table.render({
        elem: '#table'
        ,title: '列表'
        ,method: 'post'
        ,height: 'full-100'
        ,page: true //开启分页
        ,limit: 20
        ,limits: [20, 30, 40, 50, 60, 70, 80, 90, 100]
        ,loading: true
        ,cols: [
            [
                { field: 'manufacturer', title: '厂商' },
                { field: 'vendorCode', title: 'vendorCode' },
                { field: 'cardTime', title: '打卡日期' },
                { field: 'uploadDate', title: '上传日期' },
                { field: 'dutySum', title: '在职人数' },
                { field: 'dutyDLSum', title: '在职直接人数' },
                { field: 'dutyIDLSum', title: '在职间接人数' },
                { field: 'daytimeDLSum', title: '白班直接人数' },
                { field: 'daytimeIDLSum', title: '白班间接人数' },
                { field: 'daytimeSum', title: '白班总人数' },
                { field: 'nightDLSum', title: '夜班直接人数' },
                { field: 'nightIDLSum', title: '夜班间接人数' },
                { field: 'nightSum', title: '夜班总人数' },
                { field: 'daySum', title: '当日总人数' },
            ]
        ]
        ,text: {
            none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
        }
        ,data: []
        ,toolbar: '#tableToolbar'
        ,defaultToolbar: ['filter']
    });

    table.on('toolbar(table)', function(obj){
        if($("#startTime").val() == ''){
            layer.msg("请选择开始时间", {icon: 2});
            return;
        }
        if($("#endTime").val() == ''){
            layer.msg("请选择结束时间", {icon: 2});
            return;
        }
        switch (obj.event) {
            case 'find':
                table.reload('table', {
                    url: '/wc_api/getDutyAgoNext'
                    ,where: {
                        startTime:$('#startTime').val(),
                        endTime:$('#endTime').val()
                    } //设定异步数据接口的额外参数
                    ,page: {
                        curr: 1
                    }
                });
                break;
            case 'download':
                layer.confirm('确定要导出数据并下载到本地吗？', function (index) {
                    window.location.href = "/wc_api/getDutyDow?str=后&startTime=" + $('#startTime').val() + "&endTime=" + $('#endTime').val();
                    layer.close(index);
                });
                break;
            case 'reload':
                layer.confirm('确定要重新调整吗？', function (index) {
                    var indexLoad = layer.load();
                    $.post("/wc_api/getDutyAgoNext/reload", {startTime: $('#startTime').val(), endTime: $('#endTime').val()}, function (d) {
                        layer.close(indexLoad);
                        if (d.code == '200') {
                            top.layer.alert("重新调整成功", {icon: 1});
                            table.reload('table', {
                                url: '/wc_api/getDutyAgoNext'
                                ,where: {
                                    startTime:$('#startTime').val(),
                                    endTime:$('#endTime').val()
                                } //设定异步数据接口的额外参数
                                ,page: {
                                    curr: 1
                                }
                            });
                        } else {
                            top.layer.msg("重新调整失败", {icon: 2});
                        }
                        layer.close(index);
                    }, "json")
                });
                break;
        }
    })

})